window.onload=function () {
    $.ajax({
        type:"GET",
        url:"/category/getCategories",

        success:function (data) {
            //console.log(data[0].name)
            var chang=data.length
            var wyp=""
            for(var i=0;i<chang;i++){
                wyp+="<option id='"+data[i].id+"'>"
                wyp+=data[i].name
                wyp+="</option>"
            }
            $("#hide").after(wyp)
        },
        error:function () {
            console.log("error")
        }
    })
}


function CREATE() {
    var name = document.getElementById("name").value;
    var price = document.getElementById("price").value;
    var store = document.getElementById("store").value;
    var cId=$("#typppp").find("option:checked").attr("id");
    var cName="";
    var date={
        "category": {
            "id": cId,
            "name": cName,
        },
        "goods": {
            "id": 0,
            "name": name,
            "price": price,
            "store": store
        }
    };
    $.ajax({
        type:"POST",
        url:"/goods/saveOrUpdateGoods",
        dataType:"json",
        contentType: 'application/json',
        data:JSON.stringify(date),
        success:function () {
            alert("添加成功！")
            window.location.href="messageguanli.html"
        }
    })
}